package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.Admin;
import com.blacktry.entity.model.CourseDistribution;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.Course;
import com.blacktry.entity.model.Vo.Research;
import com.blacktry.entity.model.vueVO.Info;
import com.blacktry.entity.model.vueVO.TextValue;
import com.blacktry.service.CourseDistributionService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2021-12-05
 */
@Api(value = "课程分配管理模块", tags = "课程分配管理接口")
@RestController
@RequestMapping("/courseDistribution")
public class CourseDistributionController {
    @Autowired
    private CourseDistributionService courseDistributionService;

    // 看某一个教研室内教师工作安排情况
    @OperLog(operModul = "课程分配管理-看某一个教研室内教师工作安排情况",operType = OprLogConst.SELECT,operDesc = "看某一个教研室内教师工作安排情况")
    @ApiOperation("看某一个教研室内教师工作安排情况")
    @PostMapping("/distributionRoom/{page}/{size}")
    public ApiResult<Page<Research>> researchWorkGoing(@RequestBody Admin admin, @DefaultValue("1") @PathVariable("page") Integer page,@DefaultValue("6") @PathVariable("size") Integer size) {
        Page<Research> researchPage = new Page<>(page, size);
        return ApiResultHandler.buildApiResult(200, "成功",courseDistributionService.researchWorkGoing(admin, researchPage));
    }

    // 查看空余教室情况
    @OperLog(operModul = "课程分配管理-查看空余教室情况",operType = OprLogConst.SELECT,operDesc = "查看空余教室情况")
    @ApiOperation("查看空余教室情况")
    @GetMapping("/leisureClassRoom/{id}/{roomId}")
    public ApiResult<?> teacherWorkGoing(@PathVariable("id") Integer id, @PathVariable("roomId") Integer roomId) {
        // todo
        return ApiResultHandler.buildApiResult(200, "成功");
    }

    // 为课程分配教室
    @OperLog(operModul = "课程分配管理-为课程分配教室",operType = OprLogConst.SELECT,operDesc = "为课程分配教室")
    @ApiOperation("为课程分配教室")
    @GetMapping("/distributionRoom/{id}/{roomId}")
    public ApiResult<Integer> distributionRoom(@PathVariable("id") Integer id, @PathVariable("roomId") Integer roomId) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.distributionRoom(id, roomId));
    }

    // 为课程分配老师
    @OperLog(operModul = "课程分配管理-为课程分配老师",operType = OprLogConst.SELECT,operDesc = "为课程分配老师")
    @ApiOperation("为课程分配老师")
    @GetMapping("/distributionTeacher/{id}/{username}")
    public ApiResult<Integer> distributionTeacher(@PathVariable("id") Integer id, @PathVariable("username") String username) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.distributionTeacher(id, username));
    }

    // 合班
    @OperLog(operModul = "课程分配管理-合并所选班级",operType = OprLogConst.SELECT,operDesc = "合并所选班级")
    @ApiOperation("合并所选班级")
    @GetMapping("/merge")
    public ApiResult<Integer> merge(String[] ids) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.merge(ids));
    }

    // 分班
    @OperLog(operModul = "课程分配管理-差分所选班级",operType = OprLogConst.SELECT,operDesc = "差分所选班级")
    @ApiOperation("差分所选班级")
    @GetMapping("/split")
    public ApiResult<Integer> split(String[] ids) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.split(ids));
    }

    @OperLog(operModul = "课程分配管理-分页查看所有数据",operType = OprLogConst.SELECT,operDesc = "分页查看所有数据")
    @ApiOperation("分页查看所有数据")
    @PostMapping("/select/{page}/{size}")
    public ApiResult<Page<Course>> findAll(@RequestBody CourseDistribution courseDistribution, @DefaultValue("1") @PathVariable("page") Integer page, @DefaultValue("6") @PathVariable("size") Integer size) {
        System.out.println("分页查询所有分配数据");
        Page<CourseDistribution> courseDistributionPage = new Page<>(page, size);
        return ApiResultHandler.buildApiResult(200, "请求成功！", courseDistributionService.selectPageByCD(courseDistribution, courseDistributionPage));
    }



    // 根据教师名称查看所教的课程
    @OperLog(operModul = "课程分配管理-根据教师名称查看所教的课程",operType = OprLogConst.SELECT,operDesc = "根据教师名称查看所教的课程")
    @ApiOperation("根据教师名称查看所教的课程")
    @GetMapping("/selectCourseName/{userId}")
    public ApiResult<Integer> selectCourseName(@PathVariable("userId") String userId) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.selectCourseName(userId));
    }


    // 根据教师名称查看所教的课程
    @OperLog(operModul = "课程分配管理-根据教师名称和课程名查看所教的班级",operType = OprLogConst.SELECT,operDesc = "根据教师名称和课程名查看所教的班级")
    @ApiOperation("根据教师名称和课程名查看所教的班级")
    @GetMapping("/selectClassName/{userId}/{courseName}")
    public ApiResult<Integer> selectClassName(@PathVariable("userId") String userId,@PathVariable("courseName") String courseName) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.selectClassName(userId,courseName));
    }


    // 根据课程名查看所有班级
    @OperLog(operModul = "课程分配管理-根据课程名查看所有班级",operType = OprLogConst.SELECT,operDesc = "根据课程名查看所有班级")
    @ApiOperation("根据课程名查看所有班级")
    @GetMapping("/selectClassNameByCourseName/{courseName}")
    public ApiResult<String> selectClassNameByCourseName(@PathVariable("courseName") String courseName) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.selectClassNameByCourseName(courseName));
    }

    // 学生查询自己要上的课程
    @OperLog(operModul = "课程分配管理-学生查询自己要上的课程",operType = OprLogConst.SELECT,operDesc = "学生查询自己要上的课程")
    @ApiOperation("学生查询自己要上的课程")
    @GetMapping("/studentSelectCourseName")
    public ApiResult<ArrayList<TextValue>> studentSelectCourseName(Principal principal) {
        String userName=principal.getName();
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.studentSelectCourseName(userName));
    }


    // 查询教师已分配的授课情况
    @OperLog(operModul = "课程分配管理-查询教师已分配的授课情况",operType = OprLogConst.SELECT,operDesc = "查询教师已分配的授课情况")
    @ApiOperation("查询教师已分配的授课情况")
    @GetMapping("/selectTeacherNameAndAffiliation/{courseId}")
    public ApiResult<ArrayList<Info>> selectTeacherNameAndAffiliation(@PathVariable("courseId") String courseId) {
        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.selectTeacherNameAndAffiliation(courseId));
    }


//    // 根据userId查询教师已分配的课程安排
//    @OperLog(operModul = "根据userId查询教师已分配的课程安排",operType = OprLogConst.SELECT,operDesc = "根据userId查询教师已分配的课程安排")
//    @ApiOperation("根据userId查询教师已分配的课程安排")
//    @GetMapping("/selectTeacherNameAndAffiliation/{userId}")
//    public ApiResult<ArrayList<CourseRealInfo>> selectTeacherWork(@PathVariable("userId") String userId) {
//        return ApiResultHandler.buildApiResult(200, "成功", courseDistributionService.selectTeacherWork(userId));
//    }

}

